package com.leapp.sk.viewdelegate.adapter.classs

import android.content.Context
import android.text.TextUtils
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cc.vv.lkbasecomponent.util.LKScreenUtil
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideRoundTransform
import com.leapp.sk.R
import com.leapp.sk.bean.ClassAlbumEntity

/**
 * 班级相册适配器视图托管类
 * @author  chaohaipeng  on 2018/8/6.
 */
class ClassAlbumAdapterDelegate : BaseAdapterDelegate(){
    /**
     * 加载操作
     */
    var mRequestOptions: RequestOptions = RequestOptions()
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_class_album
    }

    fun setData(context: Context,data: ClassAlbumEntity){
        val iv_aca_image = getView<ImageView>(R.id.iv_aca_image)
        val tv_aca_album_name = getView<TextView>(R.id.tv_aca_album_name)
        val tv_aca_picture_num = getView<TextView>(R.id.tv_aca_picture_num)
        val layoutParams:LinearLayout.LayoutParams = iv_aca_image.layoutParams as LinearLayout.LayoutParams
        layoutParams.width=LKScreenUtil.getScreenWidth()/2-LKScreenUtil.dp2px(15f)
        layoutParams.height=LKScreenUtil.getScreenWidth()/2-LKScreenUtil.dp2px(15f)
        iv_aca_image.layoutParams=layoutParams
        if (!TextUtils.isEmpty(data.albumName)){
            tv_aca_album_name.text=data.albumName
            tv_aca_picture_num.text="${0}张图片"
            iv_aca_image.setImageResource(R.drawable.selector_album_manager_background)
        }else{
            setImage(context, "asdasdas", iv_aca_image)
            tv_aca_album_name.text="等你下课一班"
            tv_aca_picture_num.text="${321}张图片"
        }

    }
    /**
     * 设置头像和昵称
     */
    private fun setImage(context: Context, imagePath: String, imageView: ImageView) {
        /**
         * 图片圆角处理
         */
        var mGlideRoundTransform: GlideRoundTransform = GlideRoundTransform.getInstance(context)
        mGlideRoundTransform.setExceptCorner(LKScreenUtil.dp2px(5f),true,true,true,true)
        val tag = imageView.getTag(R.id.tag_image)
        mRequestOptions.diskCacheStrategy(DiskCacheStrategy.NONE)
        mRequestOptions.skipMemoryCache(true)
        mRequestOptions.error(R.mipmap.icon_test_image_album)
        mRequestOptions.transforms(mGlideRoundTransform)
            val mRequestManager = Glide.with(context)
            mRequestManager?.load(imagePath)
                    ?.apply(mRequestOptions)
                    ?.into(imageView)
            imageView.setTag(R.id.tag_image,imagePath)
    }
}